<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'menu-index', //页面标示
    'pagename' => '微信自定义菜单编辑', //当前页面名称
    'mycss' => array(), //加载的css样式表
    'myjs' => array(), //加载的js脚本
	'footerjs'=>array('content/fuelux/fuelux','content/combodate/moment.min','content/combodate/combodate'),
    'head' => true, //加载头部文件
);

include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->

<section id="content">
  <section class="main padder">
  <div class="clearfix">
    <h4><i class="fa fa-edit"></i><?php echo trim($Document['pagename'],'_');?></h4>
  </div>
  <div class="row">
    <div class="col-sm-12">
      <section class="panel">
      <div class="panel-body">
      <?php if (!isHave($rs['wx_AppId'])||!isHave($rs['wx_AppSecret'])){?>
      <div class="alert alert-warning alert-block">
        <button data-dismiss="alert" class="close" type="button"><i class="fa fa-times"></i></button>
        <h4><i class="fa fa-bell-o"></i>提示信息</h4>
        <p>请先绑定开发者信息（AppId和AppSecret） <a href="<?php echo U('home/edit');?>">立即绑定>></a></p>
      </div>
      <?php }else{?>
      <form class="form-horizontal" method="post" id="form1">
        <!-- table 11 -->
        <div class="col-lg-12">
          <section class="panel">
          <div class="panel-body">
            <div class="row text-small">
              <div class="col-sm-12 m-b-mini">
                <div id="container" style="margin:5px auto"></div>
                <div class="alert alert-warning alert-block">
                  <button data-dismiss="alert" class="close" type="button"><i class="fa fa-times"></i></button>
                  <h4><i class="fa fa-bell-o"></i>提示信息</h4>
                  <p> 1、最多只能支持3个大菜单，每个菜单下最多5个子菜单；<br/>
                    2、当多个关键字都指向一个动作时，只需设置一个关键字；<br/>
                    3、没有内容的选项（子菜单、链接）保持为空即可；<br/>
                    4、跳转链接无法获得用户身份信息，因此不适宜做游戏活动等需要识别用户的页面；<br/>
                    5、客户端菜单有一定缓存时间，如果修改后想立即查看菜单，请先取消关注再关注</p>
                </div>
              </div>
            </div>
          </div>
          <div class="table-responsive">
            <div class="form-group">
              <label class="col-sm-1 control-label">删除菜单</label>
              <div class="col-sm-10">
                <div class="row">
                  <div class="col-xs-1 radio m-l-large">
                    <label class="radio-custom">
                      <input type="radio" name="isclose" value="0" class="close-menu"  checked/>
                      <i class="fa fa-circle-o"></i><span class="red">否</span></label>
                  </div>
                  <div class="col-xs-1 radio m-l-large">
                    <label class="radio-custom">
                      <input type="radio" name="isclose" name="isclose" value="1" class="close-menu"/>
                      <i class="fa fa-circle-o"></i>是</label>
                  </div>
                </div>
                <span class="help-block">如果要关闭微信菜单请勾选“是”，则会远程删除微信菜单项目，并且下面的微信菜单设置不会生效</span> </div>
            </div>
            <div id="item-list-table">
            <table class="table table-striped b-t text-small">
              <tbody>
                <?php for($j=0;$j<3;$j+=1){
					  $menuType=isHave($data[$j]['type'])&&$data[$j]['type']=='view'?2:1;
				?>
                <tr>
                  <td height="20" scope="col"><strong>菜单名及类型</strong></td>
                  <td width="20%" scope="col">&nbsp;</td>
                </tr>
                <tr>
                  <td height="20" colspan="2" align="center">
                  <div class="form-group">
                      <label class="col-xs-1 control-label">菜单名</label>
                      <div class="col-xs-2">
                        <input type="text" class="form-control mytext" name="mainname[<?php echo $j;?>]" value="<?php echo isHave($data[$j]['name'])?$data[$j]['name']:'';?>">
                      </div>
                      <label class="col-xs-1 control-label">类型</label>
                      <div class="col-xs-2">
                        <div class="col-xs-5 radio menu-type" data-rel="1">
                          <label>
                            <input name="maintype[<?php echo $j;?>]" ismain="1" type="radio" rel="item-list-all-<?php echo $j;?>" value="1" <?php if ($menuType==1){echo 'checked';}?>>
                            普通</label>
                        </div>
                        <div class="col-xs-5 radio menu-type" data-rel="2">
                          <label>
                            <input name="maintype[<?php echo $j;?>]" ismain="1" type="radio" rel="item-list-all-<?php echo $j;?>" value="2" <?php if ($menuType==2){echo 'checked';}?>>
                            链接</label>
                        </div>
                      </div>
                      <div class="view-keyword" <?php if ($menuType==2){echo 'style="display:none"';}?>>
                          <label class="col-xs-1 control-label">关键字</label>
                          <div class="col-xs-2">
                            <input type="text" class="form-control text mytext keywords" name="mainkey[<?php echo $j;?>]" value="<?php echo isHave($data[$j]['key'])?$data[$j]['key']:'';?>">
                          </div>
                          <div class="col-xs-2">
                               <select class="select-keywords form-control">
                                  <option value="">选择关键字...</option>
                                  <?php
                                    if (isHave($keywords)){
                                        foreach($keywords as $val){
                                            if (strExists($val['keyword'],'|')){
                                                $keyword=explode('|',$val['keyword']);
                                                $keyword=isset($keyword[0])?$keyword[0]:'';
                                            }else{
                                                $keyword=$val['keyword'];	
                                            }
                                    ?>
                                  <option value="<?php echo $keyword;?>"><?php echo $val['keyword'];?></option>
                                  <?php
                                        }
                                    }
                                    ?>
                               </select>
                          </div>
                    </div>
                    <div class="view-url col-xs-6" <?php if ($menuType==1){echo 'style="display:none"';}?>>
                          <label class="col-xs-2 control-label"><strong>链接</strong></label>
                          <div class="col-xs-6">
                            <input type="text" class="form-control" name="mainurl[<?php echo $j;?>]" value="<?php echo isHave($data[$j]['url'])?urldecode($data[$j]['url']):'';?>">
                          </div>
                    </div>
                </div>
                </td>
                </tr>
              <tr>
                <td height="20" scope="col"><strong>&nbsp;&nbsp;└ 子菜单</strong></td>
                <td width="20%" scope="col">&nbsp;</td>
              </tr>
              <tr>
                <td colspan="2"><!---->
                  
                  <table width="95%" border="0" cellspacing="0" cellpadding="0" class="item-list-all" id="item-list-all-<?php echo $j;?>" <?php if ($menuType==2){echo 'style="display:none"';}?>>
                    <tbody>
                      <?php for($i=0;$i<5;$i+=1){
							 $menuType=isHave($data[$j]['sub_button'][$i]['type'])&&$data[$j]['sub_button'][$i]['type']=='view'?2:1;
						?>
                      <tr id="">
                        <td colspan="2"><!---->
                          
                          <div class="form-group">
                            <label class="col-xs-1 control-label">菜单名</label>
                            <div class="col-xs-2">
                              <input type="text" class="form-control text mytext" name="name[<?php echo $j;?>][<?php echo $i;?>]" value="<?php echo isHave($data[$j]['sub_button'][$i]['name'])?$data[$j]['sub_button'][$i]['name']:'';?>">
                            </div>
                            <label class="col-xs-1 control-label">类型</label>
                            <div class="col-xs-2">
                              <div class="col-xs-5 radio menu-type" data-rel="1">
                                <label class="">
                                  <input name="type[<?php echo $j;?>][<?php echo $i;?>]" ismain="0" type="radio" value="1" <?php if ($menuType==1){echo 'checked';}?>>
                                  普通</label>
                              </div>
                              <div class="col-xs-5 radio menu-type" data-rel="2">
                                <label class="">
                                  <input name="type[<?php echo $j;?>][<?php echo $i;?>]" ismain="0" type="radio" value="2" <?php if ($menuType==2){echo 'checked';}?>>
                                  链接</label>
                              </div>
                            </div>
                            <div class="view-keyword" <?php if ($menuType==2){echo 'style="display:none"';}?>>
                            <label class="col-xs-1 control-label">关键字</label>
                            <div class="col-xs-2">
                              <input type="text" class="form-control text mytext keywords" name="key[<?php echo $j;?>][<?php echo $i;?>]" value="<?php echo isHave($data[$j]['sub_button'][$i]['key'])?$data[$j]['sub_button'][$i]['key']:'';?>">
                            </div>
                            <div class="col-xs-2">
                              <select class="select-keywords form-control">
                                <option value="">选择关键字...</option>
                                <?php
                                        if (isHave($keywords)){
                                            foreach($keywords as $val){
                                                if (strExists($val['keyword'],'|')){
                                                    $keyword=explode('|',$val['keyword']);
                                                    $keyword=isset($keyword[0])?$keyword[0]:'';
                                                }else{
                                                    $keyword=$val['keyword'];	
                                                }
                                        ?>
                                <option value="<?php echo $keyword;?>"><?php echo $val['keyword'];?></option>
                                <?php
                                            }
                                        }
                                        ?>
                              </select>
                            </div>
                            </div>
                            <div class="view-url col-xs-6" <?php if ($menuType==1){echo 'style="display:none"';}?>>
                                <label class="col-xs-2 control-label"><strong>链接</strong></label>
                                <div class="col-xs-6">
                                    <input type="text" class="form-control" name="url[<?php echo $j;?>][<?php echo $i;?>]" value="<?php echo isHave($data[$j]['sub_button'][$i]['url'])?urldecode($data[$j]['sub_button'][$i]['url']):'';?>">
                                </div>
                            </div>
                            </div>
                          
                          <!----></td>
                      </tr>
                      <?php }?>
                    </tbody>
                  </table>
                  
                  <!----></td>
              </tr>
              <?php
				  }
				  ?>
                </tbody>
              
            </table>
          </div>
        </div>
        <div class="form-group">
          <div class="col-sm-9 col-lg-offset-1">
            <div class="col-sm-1"><button type="submit" id="sub-ok" data-loading-text="正在提交..." class="btn btn-primary">保存</button></div>
            <div class="col-md-offset-2"><button type="button" class="btn btn-white">取消</button></div>
          </div>
        </div>
        </section>
        </div>
        <!--/ table 11 -->
      </form>
      <?php }?>
    </div>
    </section>
  </div>
  </div>
</section>
</section>
<!--主体 结束--> 
<script>
$(function(){
	$(".menu-type").click(function(){
		var v=$(this).attr('data-rel');
		var ismain=$(this).attr('ismain');
		var smenu=$(this).attr('rel');
		if (v==1){
			$(this).parent().parent().find('.view-keyword').show();
			$(this).parent().parent().find('.view-url').hide();
			if (ismain){
				$('#'+smenu).show();
			}
		}else{
			$(this).parent().parent().find('.view-keyword').hide();
			$(this).parent().parent().find('.view-url').show();
			if (ismain){
				$('#'+smenu).hide();
			}
		}
	})
	$(".select-keywords").change(function(){
		$(this).parent().parent().find('.keywords').val($(this).val());	
	})
	//提交表单
	$("#form1").submit(function() {
		Msg.loading();
		$.post('<?php echo U('menu/save') ?>', $(this).serialize(), function(result) {
			Msg.hide();
			resetSubmit("#sub-ok",'保存');
			if (result.status == 1) {
				Msg.ok("保存成功");
			} else {
				Msg.error(result.info);
			}
		}, "json");
		return false;
	})
	$(".close-menu").click(function(){
		var t=$('input:radio[name="isclose"]:checked').val();
		if (t==0){
			$("#item-list-table").show();
		}else{
			$("#item-list-table").hide();
		}
	})
})
</script>
<?php
include getTpl('footer', 'public');
?>
